/*
    user
*/
import cookies from "../utils/cookies"
import { LOGIN, LOGOUT,SET_TITLE } from "./action-types"
import { combineReducers } from "redux"

/*
  用户
*/
const isLogin = cookies.get("react-token") ? true : false
const initUser = {
  username: "",
  password: "",
  isLogin,
}
function user(state = initUser, action) {
  const { type, data } = action
  switch (type) {
    case LOGIN:
      return { ...state, ...data, isLogin: true }
    case LOGOUT:
      const str = Object.keys(state)
      return { ...str, isLogin: false }
    default:
      return state
  }
}

/*
  header 标题
*/
function menuTitle(state = "首页", action) {
  const { type, data } = action
  switch (type) {
    case SET_TITLE:
      return data
    default:
      return state
  }
}

export default combineReducers({ user, menuTitle })
